<?

$thisMdl        = "MST-MODEL";

$entryBoxStyle  = " style='width:110;height:40;
                           font-size:100%;
                           font-weight:bold;' ";

$GHtml       = new CGHtml;
$GJs         = new CGJavascript;
$Misc        = new Misc;
$CLFetchers  = new CLFetchers;

$SourceDb   = new Composer;
$SourceDb   = $SourceDb->init("db");

$SourceDb->add("srcDbHdr"       ,"MST_MODEL");
$SourceDb->add("srcDbDtl"       ,"MST_MODEL_COMPOS");

//check if the user has the entry priv
if($UID->getPrivs( $thisMdl, _ENTRY_RIGHTS) > 0){

	//check entry
	$bodyPart	=	"<tr>\n".
							"  <td> ".$GHtml->formInputButton("<font size='5'>Entry</font>", // The label
        							                           "entry",                       // var Name
        							                           "entry",                       // var value
        							                           $entryBoxStyle)." </td>\n";    // var properties
}else{

	$bodyPart	=	"<tr>\n";
}

$optPrivs = "";

if($UID->getPrivs( $thisMdl, _MODIFY_RIGHTS) > 0){

	$optPrivs .=	"  <td> ".$GHtml->formInputButton( "<font size='5'>Modify</font>", // The label
            							                          "modify",                       // var Name
            							                          "Modify",                       // var value
            							                          $entryBoxStyle)." </td>\n";     // var properties
}
if($UID->getPrivs( $thisMdl, _DELETE_RIGHTS) > 0){

	$optPrivs	.=	"  <td> ".$GHtml->formInputButton( "<font size='5'>Delete</font>", // The label
            							                          "delete",                       // var Name
            							                          "Delete",                       // var value
            							                          $entryBoxStyle)." </td>\n";     // var properties
}

$propType = $GJs->jsOnFocus("GMisc.setYellow2(this);
                             Ajax.modelType(this);").

            $GJs->jsOnBlur ("GMisc.setWhite2(this);").

            $GJs->jsOnChange("this.form.submit();");

if($_POST["typeEnt"]){

  $lstType = array($_POST["typeEnt"]);
}else{

  $lstType = array();
}

//lets init the first table
echo  "<link rel=\"stylesheet\" type=\"text/css\" href=\"myMenu.css\"/>\n".

      /**
      * Global module js
      *
      */
      "<SCRIPT LANGUAGE='JavaScript' SRC='/ecs/javascript/GMisc.js'></SCRIPT> \n".

      /**
      * This module js
      *
      */
		  "<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"/ecs/tocmenu_11/javascript/misc.js\"></SCRIPT> \n".
		  "<SCRIPT LANGUAGE=\"JavaScript\" SRC=\"/ecs/tocmenu_11/javascript/ajax.js\"></SCRIPT> \n".

			"<br/><br/><br/><br/><br/>\n".
			"<form action=# name='crtList' method=post>\n".
			"<table border='1'>\n".
			"<tr>\n".

      "<td> Type </td><td> ".$GHtml->formDropDown("typeEnt",
                                                  $_POST["typeEnt"],
                                                  $lstType,
                                                  $propType)." </td>\n".

			" <td colspan='2'><input type='submit' name='criteria' 	value='Criteria'  align='left' style='width:100%; height:100%'></td></tr>\n".
			"<tr>\n".
			"  <input      type='hidden' name='view' 	value='View'>\n".
			"  <input      type='hidden' name='radioview' 	value='".$_POST["radioview"]."'>\n".
			"</form>\n".
			"</tr>\n".
			"</table>\n".
			"<table border='1'>\n".
			"<form action=tocmenu_11/viewdboredit.php method=post>\n".
			$bodyPart.
			$optPrivs.
			"</td>\n".
			"</tr>\n".
			"</table>\n";

/**
* connect to db to retrieve data with system period as the range
*
*/
$Db = new oracleDb;
$Db->init($_SESSION["ORCL"],
           $_SESSION["OPASS"],
           $_SESSION["SID"],
           _NO_COMMENT);

if ($Db->connect()) {

  switch($_POST["typeEnt"]){

    case "RAKITAN":

      $condt = "WHERE TYPE="._MODEL_TYPE_RAKITAN." ";
      break;

    case "PRODUKSI":

      $condt = "WHERE TYPE="._MODEL_TYPE_PRODUKSI." ";
      break;

    case "NORMAL":

      $condt = "WHERE TYPE="._MODEL_TYPE_NORMAL." ";
      break;

    default:

      $condt = "ORDER BY MODEL ASC";
  }

	$srcDbHdr = "MST_MODEL";

  $CLFetchers->fetchLstTransaction($Db,
            	                     $condt,
            	                     $srcDbHdr,
            	                     $nrows,
            	                     $res);

	echo  "<table border='1' class='dedeq'>\n".
      	"<tr>\n".
      	"<th> Mod    </th>\n".
      	"<th> Del    </th>\n".
      	"<th> Model  </th>\n".
	      "<th> ID     </th>\n".
      	"<th> S.N    </th>\n".
      	"<th> STATUS </th>\n".
      	"</tr>\n";

	for ($i = 0; $i < $nrows; $i++) {

	  if($res["SER_NUMBER"][$i]){

	    $isSN = 1;
	  }else{

	    $isSN = 0;
	  }

    $stdPropRow = $GJs->jsOnMouseOver("chgStyle(\"$i\",\"sBlue\");") .
                  $GJs->jsOnMouseOut ("chgStyle(\"$i\",\"sWhite\");");

    $JID  = $res["MODEL_ID"][$i];

    echo  "<tr id='$i' ".$stdPropRow.">\n".

         	  "<td> ".$GHtml->formRadio("radioview",
         	                            $JID,
         	                            _NO_PROPERTIES)."      </td>\n".

         	  "<td> ".$GHtml->formCheckBox("selbox[]",
             	                           $JID,
             	                           _NO_PROPERTIES)."  </td>\n".

            "<td> ".$res["MODEL"][$i]."      </td>\n".

            "<td> ".$res["MODEL_ID"][$i]."   </td>\n".

            "<td> ".$res["SER_NUMBER"][$i]." </td>\n".

            "<td> ".$res["STATUS"][$i]."     </td>\n".

          "</tr>\n";

	}

	echo  "</table>\n".
				"<br/>\n".
				"</form>\n".
				"</div>\n";

	$Db->dc();
}else{

  $Misc->usrDie("DB connection failed");
}

session_commit();

?>